package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.VacationService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述 考勤管理-->请假管理
 * @创建人 zm
 * @创建时间 2020/3/26
 */
@RestController
@RequestMapping("/vacation")
public class VacationController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private VacationService service;


    /**
     * @描述 组合查询学生请假信息情况
     * @创建人 zm
     * @创建时间 2020/3/26
     */
    //@RequestMapping("/queryStudentVacationAll")
    /*public Result queryStudentVacationAll(RequestParameterWrapper request,
                                          @RequestParam(value = "classId", required = false) Integer classId,
                                          @RequestParam(value = "state", required = false) Integer state,
                                          @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                          @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        String schoolId = request.getParam("schoolId");
        logger.info("VacationController==>queryStudentVacationAll,schoolId={}", schoolId);
        return service.queryStudentVacationAll(indexNo, classId, Integer.parseInt(schoolId), state, rows);
    }*/


    /**
     * @Author zm
     * @Description 组合查询学生请假信息情况 2.0
     * @Date 2020/8/14 14:55
     */
    @RequestMapping("/queryStudentVacationAll")
    public Result queryStudentVacationAll(RequestParameterWrapper request,
                                          @RequestParam(value = "classId", required = false) Integer classId,
                                          @RequestParam(value = "state", required = false, defaultValue = "0") Integer state,
                                          @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                          @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        logger.info("VacationController==>queryStudentVacationAll,schoolId={}", schoolId);
        //return service.queryStudentVacationAll(indexNo, classId, Integer.parseInt(schoolId), state, rows);
        return service.queryStudentVacationAll2(indexNo, Integer.parseInt(teacherId), Integer.parseInt(schoolId), state, rows,classId);
    }




    /**
     * @描述 修改请假状态
     * @创建人 zm
     * @创建时间 2020/3/26
     */
    //@RequestMapping("/updateStudentVacationState")
    public Result updateStudentVacationState(RequestParameterWrapper request,
                                             @RequestParam(value = "id") Integer id,
                                             @RequestParam(value = "state") Integer state) {
        String teacherId = request.getParam("teacherId");
        logger.info("VacationController==>updateStudentVacationState,id={},state={},teacherId={}", id, state, teacherId);
        long l = service.updateStudentVacationState(id, state, Integer.parseInt(teacherId));
        if (l > 0) {
            return new Result();
        }
        return new Result(CodeUtil.MODIFICATION_FAILED);
    }

}
